package com.burger.counter.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import com.burger.counter.Constants.SQLConstants;
import com.burger.counter.beans.Kids;

import com.burger.counter.util.DBConnection;

public class KidsDao {

	
	public Kids[] getKidsDetails(int regionId){
		Connection con=null;
		ResultSet rs=null;
		PreparedStatement prest =null;
		Kids kidslist[]=null;
		int size;
		try{
			con=DBConnection.getConnection();
			System.out.println("Creating DB Connection");
			String prepStatement=SQLConstants.getKids;
			prest = con.prepareStatement(prepStatement);
			prest.setInt(1,regionId);
		
			rs = prest.executeQuery();
			if (rs != null) {
				rs.last();
				size = rs.getRow();
				kidslist = new Kids[size];
				int currRow = 0;
				rs.beforeFirst();
				
				while (rs.next()) {
					Kids p = new Kids();
					p.setKidsId(rs.getInt(1));
					p.setKidsName(rs.getString(2));
					p.setKidsDesc(rs.getString(3));
					p.setKidsPrice(rs.getDouble(4));
					
					kidslist[currRow] = p;
			
					currRow++;
				}
			}		
		}
		catch(Exception e){
			e.printStackTrace();
		}
		
		return kidslist;
	}

	public void setKidsCount(int regionId,String kidsName){
		Connection con=null;
		int rs;
		PreparedStatement prest =null;
		try{
			con=DBConnection.getConnection();
			System.out.println("Creating DB Connection");
			String prepStatement=SQLConstants.updateKidsCount;
			prest = con.prepareStatement(prepStatement);
			prest.setInt(1,regionId);
			prest.setString(2, kidsName);
			
			rs = prest.executeUpdate();
			if (rs ==1) {
				System.out.println("Kids Count has been updated");
			}					
		}
		catch(Exception e){
			
		}		
	}
}

	